﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kooboo.HtmlFunc.Providers;

namespace Kooboo.CMS.SiteConverter.Parser.NVelocity
{
    public class ListParser : ParserBase, IParser<IList>
    {
        #region IParser<IList> Members

        public void Parse(IList obj)
        {
            var loopStartFormat = @"
#foreach ($item in $ViewBag.{0})
#each
";
            var blockFormat = @"$ViewHelper.Edit($item)";
            var fieldFormat = @"$ViewHelper.EditField($item, ""{0}"")"; //var fieldFormat = @"$item.{0}";
            var linkFormat = @"$Url.FrontUrl().PageUrl(""{0}"", ""%{{UserKey = $item.UserKey}}"")";
            var imageSrcFormat = @"$Url.Content($item.{0})";
            var loopEndFormat = @"
#end";
            var pagerFormat = @"
<div class=""pager"">
    $Html.FrontHtml().Pager($ViewBag.{0})
</div>";

            Razor.ListParser.FillResult(this.Context, obj, this.EngineName, loopStartFormat, loopEndFormat, blockFormat, fieldFormat, linkFormat, imageSrcFormat, pagerFormat);
        }

        #endregion
    }
}
